<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">-->
    <title>Test</title>
</head>
<body>

<script>
    /**
     * @param {number[]} nums
     * @param {number} target
     * @return {number[]}
     */
    var twoSum = function (nums, target) {
        for (var i = 0; i < nums.length; i++) {
            var hehe = target - nums[i];
            for (var j = i + 1; j < nums.length; j++) {
                if (hehe === nums[j]) {
                    return [i, j];
                }
            }
        }
    };

    /**
     * @param {number[]} nums
     * @param {number} target
     * @return {number[]}
     */
    var twoSum2 = function (nums, target) {
        var he = {};
        for (var i = 0; i < nums.length; i++) {
            var sum = target - nums[i];

            var k = "s" + sum;
            if (he[k] !== undefined) {
                return [he[k], i];
            }
            he["s" + nums[i]] = i;
        }
        // console.log(he);
    };


    var rs1 = twoSum([2, 7, 22, 11, 34, 55], 9);
    var rs2 = twoSum2([2, 7, 22, 11, 34, 55], 9);
    // console.log(rs1);
    console.log(rs2);

</script>
</body>
</html>